package com.itqf.controller;

import com.itqf.entity.Users;
import com.itqf.utils.R;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/17
 * @Time: 上午11:45
 */
@RestController  //每个方法都响应json   @ResponseBody @Controller
//@CrossOrigin("http://localhost:63343")//允许http://localhost:63343 跨域访问
@CrossOrigin("*")//允许http://localhost:63343 跨域访问
public class MyRestController {


    //localhost:8080/users  get   查
    //localhost:8080/users  post   新增
    //localhost:8080/users  put   修改
    //localhost:8080/users/1 delete     删除

    //@RequestMapping(value = "/users",method = RequestMethod.GET)//默认能处理所有方式的请求   get  post  delete put  head  patch
    @GetMapping("/users") //等价
    public R   findAll(){
        System.out.println("get--->查");

        return   R.ok();
    }

    @PostMapping("/users") //等价
    // {"id":1,"username":"admin"}
    public R add(@RequestBody Users users){
        System.out.println("post--->add"+users);
        //调用service
        return  R.ok("新增成功").put("users",users);
    }

    @PutMapping("/users") //等价
    public R put(@RequestBody Users users){
        System.out.println("put--->update"+users);
        return  R.ok("修改成功").put("users",users);

    }
    @DeleteMapping("/users/{id}") //等价
    public R  delete(@PathVariable int id){
        System.out.println("delete--->删除"+id);
        return  R.ok("删除成功");
    }



}
